package net.bithappens.hnqe.query;

import java.util.Arrays;

import net.bithappens.hnqe.IllegalParamException;
import net.bithappens.hnqe.query.LogicalOperation.Operator;


public class ConstraintCompare extends Constraint{
	
	public enum ConstraintType {
		EQUAL(1),
		NONEQUAL(1),
		GREATHER(1),
		GREATHEREQUAL(1),
		LESS(1),
		LESSEQUAL(1),
		MATCHREGEX(1);
				
		private int paramCount;
		
		private ConstraintType(int paramCount) {
			this.paramCount = paramCount;
		}
		
		private void checkValidParamSet(ConstraintType type, Atom... params) throws IllegalParamException{
			if(params == null){
				throw new IllegalParamException("NULL values for the constrain parameters are not allowes");
			}
			
			if(params.length != paramCount){
				throw new IllegalParamException("The current param count doesn't match the required param count of "+paramCount);
			}
		}

	} 
	
	private ConstraintType constraintType;
	
	private Atom[] params;

	public ConstraintCompare(Atom constrainee, ConstraintType constraintType, Atom... params) throws Exception {
		if(constrainee == null){
			throw new IllegalParamException("The constrainee is not allowed to be NULL");
		}
		constraintType.checkValidParamSet(constraintType, params);
		
		this.constrainee = constrainee;
		this.constraintType = constraintType;
		this.params = params;
	}


	public ConstraintType getConstraintType() {
		return constraintType;
	}

	@Override
	public Atom[] getParams() {
		return params;
	}

	@Override
	public String toString() {
		return "[CompareConstraint| "+constrainee+"{" + constraintType.name() + "} " + Arrays.toString(params) + "]";
	}
}
